package com.trainoo.mina.codec;

/**
 * @Auther: zt
 * @Date: 2020/4/14 16:11
 * @Description:
 */
public class MessagePack {
    /**
     * 0x00表示请求
     */
    public static final byte REQUEST = 0x00;
    /**
     * 0x01表示回复
     */
    public static final byte RESPONSE = 0x01;

    // 总长度（长度的字节 + 包体长度字节）
    private int len;

    private String content;

    // 构造方法设置协议
    public MessagePack(String content) {
        this.content = content;
        // len的长度4个字节， 内容的字节数
        this.len = 4 + (content == null ? 0 : content.getBytes().length);
    }

    public int getLen() {
        return len;
    }

    public void setLen(int len) {
        this.len = len;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @Override
    public String toString() {
        return "MessagePack{" +
                "len=" + len +
                ", content='" + content + '\'' +
                '}';
    }
}
